package com.ssy.lingxi.marketing.serviceimpl.feign;

import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.marketing.service.feign.IPlatformManageFeignService;
import com.ssy.lingxi.platform.manage.api.feign.inner.ShopControllerFeign;
import com.ssy.lingxi.platform.manage.api.model.dto.common.CommonIdListDTO;
import com.ssy.lingxi.platform.manage.api.model.vo.shop.ShopVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 平台管理内部接口
 * @author yzc
 * @version 2.0.0
 * @date 2021/7/19
 */
@Service
public class PlatformManageFeignServiceImpl implements IPlatformManageFeignService {

    @Resource
    private ShopControllerFeign shopControllerFeign;

    @Override
    public Wrapper<List<ShopVO>> shopByIdList(List<Long> idList) {
        CommonIdListDTO commonIdListRequest = new CommonIdListDTO();
        commonIdListRequest.setIdList(idList);
        return shopControllerFeign.byShopIds(commonIdListRequest);
    }

    @Override
    public Wrapper<List<ShopVO>> shopAll() {
        return shopControllerFeign.shopAll();
    }

    @Override
    public Map<Long,ShopVO> shopMapByIdList(List<Long> idList) {
        CommonIdListDTO commonIdListRequest = new CommonIdListDTO();
        commonIdListRequest.setIdList(idList);
        Wrapper<List<ShopVO>> listWrapper = shopControllerFeign.byShopIds(commonIdListRequest);
        if(listWrapper.getCode()== ResponseCode.SUCCESS.getCode()&& !CollectionUtils.isEmpty(listWrapper.getData())){
            return listWrapper.getData().stream().collect(Collectors.toMap(k ->k.getId(),v->v,(v1,v2)->v1));
        }else{
            return null;
        }
    }
}
